from tkinter import *
from tkinter import ttk  #导入ttk模块，因为Combobox下拉菜单控件在ttk中
root = Tk()
root.title("串口调试助手")
#root.geometry("800x600")
def MenuCallback1():
    print("另存为")

def MenuCallback2():
    print("关闭")

def MenuCallback3():
    print("截图")
menubar = Menu(root)  #创建一个顶级菜单
filemenu = Menu(menubar,tearoff = False) #创建一个子菜单filemenu，长在顶级菜单menubar下
menubar.add_cascade(label = "文件",menu = filemenu) #为子菜单filemenu取个名字,长在顶级菜单menubar下
filemenu.add_command(label = "另存为",command = MenuCallback1) #为子菜单filemenu添加选项，取名"另存为"
filemenu.add_command(label = "关闭",command = MenuCallback2)  #为子菜单filemenu添加选项，取名"关闭"

#同样的下面再在顶级菜单下创建一个"工具"
toolmenu = Menu(menubar,tearoff = False)
menubar.add_cascade(label = "工具",menu = toolmenu)
toolmenu.add_command(label = "截图",command = MenuCallback3)


root.config(menu = menubar)

group_serial_set = LabelFrame(root,text = "串口设置")
group_serial_set.grid(row = 0,column = 1)
serial_label = Label(group_serial_set,text = "串口号")
serial_label.grid(row = 1,column = 1,sticky = W)
serial_combobox = ttk.Combobox(group_serial_set,width = 8)
serial_combobox['value'] = ("COM0","COM1","COM2","COM3")
serial_combobox.grid(row = 1,column = 2)

bound_label = Label(group_serial_set,text = "波特率")
bound_label.grid(row = 2,column = 1)
bound_combobox = ttk.Combobox(group_serial_set,width = 8)
bound_combobox['value'] = ("9600","19200","115200","921600")
bound_combobox.grid(row = 2,column = 2)

databits_label = Label(group_serial_set,text = "数据位")
databits_label.grid(row = 3,column = 1)
databits_combobox = ttk.Combobox(group_serial_set,width = 8)
databits_combobox['value'] = ("1","1.5","2")
databits_combobox.grid(row = 3,column = 2)

checkbits_label = Label(group_serial_set,text = "校验位")
checkbits_label.grid(row = 4,column = 1)
checkbits_combobox = ttk.Combobox(group_serial_set,width = 8)
checkbits_combobox['value'] = ("奇校验","偶校验","无校验")
checkbits_combobox.grid(row = 4,column = 2)


recv_set_v = IntVar()
recv_set = LabelFrame(root,text = "接收设置")
recv_set.grid(row = 1,column = 1)
recv_set_radiobutton1 = Radiobutton(recv_set,text = "ASCII",variable = recv_set_v,value = 1)
recv_set_radiobutton1.grid(row = 6,column = 1,sticky = W)
recv_set_radiobutton2 = Radiobutton(recv_set,text = "HEX",variable = recv_set_v,value = 2)
recv_set_radiobutton2.grid(row = 6,column = 2,sticky = W)

recv_set_v2 = IntVar()
recv_set_v3 = IntVar()
recv_set_v4 = IntVar()
recv_set_checkbutton1 = Checkbutton(recv_set,text = "自动换行",variable = recv_set_v2)
recv_set_checkbutton1.grid(row = 7,column = 1)
recv_set_checkbutton2 = Checkbutton(recv_set,text = "显示发送",variable = recv_set_v3)
recv_set_checkbutton2.grid(row = 8,column = 1)
recv_set_checkbutton3 = Checkbutton(recv_set,text = "显示时间",variable = recv_set_v4)
recv_set_checkbutton3.grid(row = 9,column = 1)


def RecvTimeCallback():
    print(send_set_v7.get())
    
send_set_v5 = IntVar()
send_set_v6 = IntVar()
send_set_v7 = IntVar()
send_set = LabelFrame(root,text = "发送设置")
send_set.grid(row = 2,column = 1)
send_set_radiobutton3 = Radiobutton(send_set,text = "ASCII",variable = send_set_v5,value = 3)
send_set_radiobutton3.grid(row = 11,column = 1,sticky = W)
send_set_radiobutton4 = Radiobutton(send_set,text = "HEX",variable = send_set_v5,value = 4)
send_set_radiobutton4.grid(row = 11,column = 2)
send_set_checkbutton4 = Checkbutton(send_set,text = "重复发送",variable = send_set_v6)
send_set_checkbutton4.grid(row = 12,column = 1)
Label(send_set,text = "时间间隔：").grid(row = 13,column = 1,sticky = W)
Spinbox(send_set,from_ = 0,to = 9999,textvariable = send_set_v7,command = RecvTimeCallback,width = 6).grid(row = 13,column = 2,sticky = W)

def SendCallback():
    print("发送")
    
framRCV = Frame(root,width = 500,height = 250)
framRCV.grid(row = 0,column = 2,rowspan = 2)
Text(framRCV,width = 60,height = 17,pady = 10).grid(row = 0,column = 1)
framSEND = Frame(root,width = 500,height = 80)
framSEND.grid(row = 2,column = 2)
Text(framSEND,width = 50,height = 5,pady = 10).grid(row = 0,column = 1)
Button(framSEND,text = "发送",padx = 20,command = SendCallback).grid(row = 0,column = 2)

mainloop()
